To migrate this application to the RDC, remove the OCX component from Form1, and remove the Crystal Report Control from the Project|Components menu, in addition to the steps below:
Reference the Crystal Report 8 ActiveX Designer Runtime Library
Add the Crystal Report Viewer Control to Form2
The properties and methods are accessed from individual objects. Following this code sample is a detailed description on the RDC Automation Servers Object Model.
The RDC will open a standard Crystal Report (.RPT). The Report could have been Imported into or recreated in the RDC ActiveX Designer (.DSR).
Declare the application object used to open the rpt file.
Dim crxApplication As New CRAXDRT.Application
Public Report As CRAXDRT.Report
Declare a DatabaseTable object for setting the location of the database. This object will be used for the main and subreport.
Dim crxDatabaseTable As CRAXDRT.DatabaseTable
Declare a ParameterFieldDefinition object for passing parameters.
Dim crxParameterField As CRAXDRT.ParameterFieldDefinition
Declare a Report object to set to the subeport.
Dim crxSubreport As CRAXDRT.Report
Declare a FormulaFieldDefinition object for passing formulas.
Dim crxFormulaField As CRAXDRT.FormulaFieldDefinition
Set Report = crxApplication.OpenReport _
(App.Path & "\OCX_to_RDC.rpt", 1)
Use a For Each loop to change the location of each DatabaseTable in the Reports DatabaseTable Collection.
For Each crxDatabaseTable In Report.Database.Tables
crxDatabaseTable.Location = App.Path & "\xtreme.mdb"
Set crxParameterField to the first parameter in the parameterfields collection of the main report.
Set crxParameterField = Report.ParameterFields.Item(1)
Pass the value to the main report.
crxParameterField.AddCurrentValue "Main Report Parameter"
Set crxSubreport to the subreport 'Sub1' of the main report. The subreport name needs to be known to use this method.
Set crxSubreport = Report.OpenSubreport("Sub1")
Use a For Each loop to change the location of each DatabaseTable in the Subreport Database Table Collection.
For Each crxDatabaseTable In
crxSubreport.Database.Tables
crxDatabaseTable.Location = App.Path &
"\xtreme.mdb"
Set crxFormulaField to the first formula in the formulafields collection of the subreport.
Set crxFormulaField = crxSubreport.FormulaFields.Item(1)
Pass the formula to the subreport.
crxFormulaField.Text = "'Subreport Formula'"
Call Form2 to preview the Report.
Select the printer for the report passing the Printer Driver, Printer Name and Printer Port.
Report.SelectPrinter "HPPCL5MS.DRV", "HP LaserJet 4m Plus", "\\Vanprt\v1
Print the Report without prompting the user.
Declare an ExportOptions Object.
Dim crxExportOptions As CRAXDRT.ExportOptions
Set crxExportOptions to the Report object's ExportOptions.
Set crxExportOptions = Report.ExportOptions
Set the report to be exported to Rich Text Format.
crxExportOptions.FormatType = crEFTRichText
Set the destination type to disk.
crxExportOptions.DestinationType = crEDTDiskFile
Set the path and name of the exported document.
crxExportOptions.DiskFileName = App.Path & "\RDCExport.rtf"
Export the report without prompting the user.
Private Sub Form_Load()
Set the Report source for the Crystal Report Viewer to the Report.
CRViewer1.ReportSource = Form1.Report
This code resizes the Report Viewer control to Form2's dimensions.
CRViewer1.Height = ScaleHeight
Seagate Software IMG Holdings, Inc. http://www.seagatesoftware.com Support services: http://support.seagatesoftware.com |